clc
clear

% trel = struct('numInputSymbols', 2, 'numOutputSymbols', 4, 'numStates', 4,...
%               'nextStates', [0 1; 2 3; 0 1; 2 3],...
%               'outputs',    [0.9 3.9; 2 1; 3 0; 1 2]);

% [isok,status] = istrellis(trel)
          
trel = poly2trellis(2,[3 2]);

K     = log2(trel.numStates) + 1; % кодовое ограничение
tblen = 5 * K;



msg = [1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];


code = convenc(msg, trel);


decoded = vitdec(code,trel,tblen,'cont','hard');


[n,r] = biterr(decoded(tblen+1:end),msg(1:end-tblen));
disp(['Вероятность ошибки на бит: ',num2str(r)])